package models

import (
	"time"
	"xorm.io/builder"
)

type OaLog struct {
	Id         int `xorm:"not null pk autoincr INT(11)"`
	Operator   string
	UserId     int
	Controller string
	Param      string
	Ip         string
	AddTime    time.Time
}

func (o *OaLog) AddLog() error {
	_, err := engine.Table("oa_log").Insert(o)
	return err
}

func (o *OaLog) UserLogList(filter builder.Cond, pageSize int, offset int) (list []*OaLog, count int64, err error) {
	if err = engine.Table("oa_log").Alias("o").
		//Where("o.user_id = ?", userId).
		And(filter).Limit(pageSize, offset).Desc("o.id").Find(&list); err != nil {
		return list, 0, err
	}
	count, err = engine.Table("oa_log").Alias("o").
		//Where("o.user_id = ?", userId).
		And(filter).Count()
	if err != nil {
		return nil, 0, err
	}
	return
}
